package team.seekers.hula.island.postComment.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import team.seekers.hula.common.annotation.ApiResponseBody;
import team.seekers.hula.common.entity.PageResult;
import team.seekers.hula.island.postComment.entity.dto.PostCommentQueryDTO;
import team.seekers.hula.island.postComment.entity.vo.PostCommentInfoVO;
import team.seekers.hula.island.postComment.service.IslandPostCommentReplyService;
import team.seekers.hula.auth.service.MindUtils;
import team.seekers.hula.island.postComment.entity.dto.PostCommentDTO;
import team.seekers.hula.island.postComment.entity.dto.PostCommentListDTO;
import team.seekers.hula.island.postComment.entity.vo.PostCommentListVO;
import team.seekers.hula.island.postComment.service.IslandPostCommentService;

import java.util.List;

/**
 * @author ekin
 * @Description GOOD
 * @mood happy
 */
@Controller
@ApiResponseBody
@RequestMapping("/post/comment")
public class PostCommentController {

    @Autowired
    private IslandPostCommentService islandPostCommentService;

    @Autowired
    private IslandPostCommentReplyService islandPostCommentReplyService;

    /**
     * info
     */
    @GetMapping("/info")
    public PostCommentInfoVO commentInfo(@RequestParam String id) {
        return islandPostCommentService.info(id);
    }

    /**
     * 共创帖子评论
     */
    @PostMapping("/add")
    public PostCommentListVO postComment(@RequestBody PostCommentDTO postCommentDTO) {
        postCommentDTO.setUserId(MindUtils.getUserId());
        return islandPostCommentService.postComment(postCommentDTO);
    }

    /**
     * list
     */
    @GetMapping("/list")
    public List<PostCommentListVO> listComment(PostCommentListDTO postCommentListDTO) {
        return islandPostCommentService.listAllComment(postCommentListDTO);
    }

    /**
     * list
     */
    @GetMapping("/remove")
    public void remove(@RequestParam String id) {
        islandPostCommentService.delete(id);
    }

    /**
     * 给评论点赞或取消点赞
     */
    @GetMapping("/like-or-cancel")
    public void likeOrCancel(@RequestParam String commentId) {
        islandPostCommentService.likeOrCancel(commentId, MindUtils.getUserId());
    }

    @GetMapping("/page")
    public PageResult<PostCommentListVO> pageComment(PostCommentQueryDTO postCommentQueryDTO) {
        return islandPostCommentService.pageComment(postCommentQueryDTO);
    }
}
